package com.ruoyi.system.service.impl;

import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.function.Function;

/**
 * 公众号爬虫
 * <pre>
 *     支持标题过滤的
 * </pre>
 *
 * @author woo
 * @date 2021/7/29
 */
@Slf4j
public class FilterOfficialAccountsReptile extends OfficialAccountsReptile {

	private Function<Map<String, Object>, Boolean> filter;

	public FilterOfficialAccountsReptile(Long state, String fakeid, Function<Map<String, Object>, Boolean> filter) {
		super(state, fakeid);
		this.filter = filter;
	}

	/**
	 * 包含title保存
	 *
	 * @param state
	 * @param fakeid
	 * @param containTitle
	 */
	public FilterOfficialAccountsReptile(Long state, String fakeid, String containTitle) {
		super(state, fakeid);
		this.filter = params -> {
			String title = this.parseTitle(params);
			if (!title.contains(containTitle)) {
				return false;
			}
			return super.filter(params);
		};
	}

	@Override
	public Boolean filter(Map<String, Object> param) {
		return filter.apply(param);
	}
}
